<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<HTML>
<HEAD>
  	<base href="<%=basePath%>">
<TITLE>DAWU WebServer Home</TITLE>
<LINK REL="stylesheet" HREF="css/dwdoor.css" TYPE="text/css">
<link rel="stylesheet" type="text/css" href="css/index.css">
<link rel="stylesheet" type="text/css" href="css/custom_select.css">
<link rel="stylesheet" type="text/css" href="css/jquery-ui.css" />
<meta http-equiv="Content-Type" content="text/html;charset=utf-8"/>
<script type="text/javascript" src="js/jquery-1.7.2.min.js"></script>
<script type="text/javascript" src="js/jquery.csf.js"></script>
<script type="text/javascript" src="js/jquery-cookie.js"></script>
<script type="text/javascript" src="lang/b28n.js"></script>
<script type="text/javascript" src="js/func.js"></script>
<script type="text/javascript" src="js/base64.min.js"></script>
<script type="text/javascript">
</script>
</HEAD>

<BODY onLoad="">
<div class="contain">

<!-- ================= SNUM/WEBADD/CARMEADD Settings ================= -->
<div class="sec" id="div_date">
<div class="title">服务器参数设置</div>
<form method=post id="dwGateSetting" name="dwGateSetting" action="/dw/Dwbrowser" >
    <div class="content">
        <div>
            <ul>                
				<li class="necessary  spec">
                    <span class="name">服务器 IP</span>
                    <span class="conn" style="margin-left: 20px;">
                        <input class="text" type="text" size="24" name="WebADDR" maxlength="96" value="10.10.10.239" type="text" >
                    </span>
                </li>
				<li class="necessary  spec">
                    <span class="name">服务器 PORT</span>
                    <span class="conn" style="margin-left: 20px;">
                        <input class="text" type="text" size="24" name="WebPORT" maxlength="9" value="80" type="text" >
                    </span>
                </li>
                <li class="necessary  spec">
                    <span class="name">结果返回路径</span>
                    <span class="conn" style="margin-left: 20px;">
                        <input class="text" type="text" size="24" name="cmdresult"  id="CMDresult" maxlength="96" value="" type="text" >
                    </span>
                </li>
                <li class="necessary  spec">
                    <span class="name">实时上传路径</span>
                    <span class="conn" style="margin-left: 20px;">
                        <input class="text" type="text" size="24" name="realtime"  id="REALtime" maxlength="96" value="" type="text" >
                    </span>
                </li>
                <li class="necessary  spec">
                    <span class="name">定时连接路径</span>
                    <span class="conn" style="margin-left: 20px;">
                        <input class="text" type="text" size="24" name="DetectDevice"  id="DETECTDevice" maxlength="96" value="" type="text" >
                    </span>
                </li>
				<li class="necessary  spec">
                    <span class="name">一号门摄像头 IP</span>
                    <span class="conn" style="margin-left: 20px;">
                        <input class="text" type="text" size="24" name="Camera0ADDR" id="Camera0ADDR" maxlength="15" value="" type="text" >
                    </span>
                </li>
				<li class="necessary  spec">
                    <span class="names">一号门摄像头 PORT</span>
                    <span class="conn" style="margin-left: 6px;">
                        <input class="text" type="text" size="24" name="Camera0PORT" maxlength="8" value="" type="text" >
                    </span>
                </li>
				<li class="necessary  spec">
                    <span class="name">二号门摄像头 IP</span>
                    <span class="conn" style="margin-left: 20px;">
                        <input class="text" type="text" size="24" name="Camera1ADDR" id="Camera1ADDR" maxlength="15" value="" type="text" >
                    </span>
                </li>
				<li class="necessary  spec">
                    <span class="names">二号门摄像头 PORT</span>
                    <span class="conn" style="margin-left: 6px;">
                        <input class="text" type="text" size="24" name="Camera1PORT" maxlength="8" value="" type="text" >
                    </span>
                </li>
				<li class="necessary  spec">
                    <span class="name">三号门摄像头 IP</span>
                    <span class="conn" style="margin-left: 20px;">
                        <input class="text" type="text" size="24" name="Camera2ADDR" id="Camera2ADDR" maxlength="15" value="" type="text" >
                    </span>
                </li>
				<li class="necessary  spec">
                    <span class="names">三号门摄像头 PORT</span>
                    <span class="conn" style="margin-left: 6px;">
                        <input class="text" type="text" size="24" name="Camera2PORT" maxlength="8" value="" type="text" >
                    </span>
                </li>
				<li class="necessary  spec">
                    <span class="name">四号门摄像头 IP</span>
                    <span class="conn" style="margin-left: 20px;">
                        <input class="text" type="text" size="24" name="Camera3ADDR" id="Camera3ADDR" maxlength="15" value="" type="text" >
                    </span>
                </li>
				<li class="necessary  spec">
                    <span class="names">四号门摄像头 PORT</span>
                    <span class="conn" style="margin-left: 6px;">
                        <input class="text" type="text" size="24" name="Camera3PORT" maxlength="8" value="" type="text" >
                    </span>
                </li>
				<li class="necessary  spec">
                    <span class="name">设备访问间隔时间</span>
                    <span class="conn" style="margin-left: 20px;">
                        <input class="text" type="text" size="24" name="reQusttime" maxlength="8" value="15" type="text">
                    </span>
                </li>
                <li class="necessary  spec">
                    <span class="name">软件版本</span>
                    <span class="conn" style="margin-left: 20px;">
                        <input class="text" type="text" size="24" name="sVersion" id="sVersion" maxlength="15" value="2016V09.01DSR" type="text" readonly="1">
                    </span>
                </li>				
            </ul>
        </div>
    </div>
  <div class="btn-part">
    <div class="button-container">
    <!--<button id="manApply" class="button-button btn-pre" type="button"  type=submit   onclick='dwGatesubmit();'>提交</button>
    <button id="manCancel" class="button-button btn-next" type="button"  type=reset   >取消</button>              
    <button id="manDownLoad" class="button-button btn-pre" type="button"  type=submit   onclick='dwDownLoad();'>下发</button>-->
	<button id="manDownLoad" class="button-button btn-pre" type="button"  type=submit   onclick='dwGateSettingCheck();'>下发</button>
	</div>
  </div>
</form>
</div>
<div class="sec" id="div_date">
<div class="title">固件升级</div>
 <form method="post" id="ImportPics"  name="ImportPics" action="/dwsupdate.php" enctype="multipart/form-data">
    <div class="content">
      <div>
        <ul>
		  <li class="necessary  spec">
            <span class="name">选择设备号</span>
            <span class="conn ">
			  <select onchange="settab(this[selectedIndex].value,'');" name="ControlerN" id="controlerN">                        
	    	  </select>
			  <input type="text" name="controlernum" style="display:none" value="test"/>
            </span>
          </li>
          <li class="necessary">
            <span class="name long">选择升级文件</span>
            <span class="conn ">
              <!--<img id="stafpic" src="/images/touxiang2.png" alt="staff picture" width="60px" height="60px" style="display:inline-block;"/>-->
        	  <input type="File" id="fileName" name="filename" size="20" maxlength="256" onchange="" style="vertical-align: top;margin-top:5px;"/>
            </span>
          </li>
        </ul>
      </div>
    </div>
    <div class="btn-part">
      <div class="button-container">
        <button id="manApply1" class="button-button btn-pre" type="button"  type=submit onclick='return checkfile();'>提交</button>
        <button id="manCancel1" class="button-button btn-next" type="button"  type=reset   >取消</button>                      
	    <!--<button id="manDownLoad1" class="button-button btn-pre" type="button"  type=submit   onclick='dwDownLoadfile();'>下发</button>-->
	  </div>
    </div> 
 </form>
</div>

</div>
</BODY>
<script type="text/javascript">
function dwGateSettingCheck()
{
	var WebADDR=document.dwGateSetting.WebADDR;
	var WebADDRv=document.dwGateSetting.WebADDR.value;
	var WebPORT=document.dwGateSetting.WebPORT.value;
	var Camera0ADDR=document.dwGateSetting.Camera0ADDR;
	var Camera0ADDRv=document.dwGateSetting.Camera0ADDR.value;
	var Camera0PORT=document.dwGateSetting.Camera0PORT.value;
	var Camera1ADDR=document.dwGateSetting.Camera1ADDR;
	var Camera1ADDRv=document.dwGateSetting.Camera1ADDR.value;
	var Camera1PORT=document.dwGateSetting.Camera1PORT.value;
	var Camera2ADDR=document.dwGateSetting.Camera2ADDR;
	var Camera2ADDRv=document.dwGateSetting.Camera2ADDR.value;
	var Camera2PORT=document.dwGateSetting.Camera2PORT.value;
	var Camera3ADDR=document.dwGateSetting.Camera3ADDR;
	var Camera3ADDRv=document.dwGateSetting.Camera3ADDR.value;
	var Camera3PORT=document.dwGateSetting.Camera3PORT.value;
	var cmdresultpath = document.dwGateSetting.cmdresult.value;
	var realtimepath = document.dwGateSetting.realtime.value;
	var DetectDevicepath = document.dwGateSetting.DetectDevice.value;
	var reQusttime=document.dwGateSetting.reQusttime.value;
/*	if(!checkIp(WebADDR))
    {
        if($.cookie('language') === "en")
		    alert( "Please input server ADDR right." );
		if($.cookie('language') != "en")
		    alert( "请正确输入服务器IP。" );
        document.dwGateSetting.WebADDR.focus();
        return false;
    }*/
	if(cmdresultpath=='')
	{
		 if($.cookie('language') === "en")
		    alert( "Please input cmdresultpath." );
		if($.cookie('language') != "en")
		    alert( "请输入结果返回路径。" );
        document.dwGateSetting.WebPORT.focus();
        return false;
	}
	if(realtimepath=='')
	{
		 if($.cookie('language') === "en")
		    alert( "Please input realtimepath." );
		if($.cookie('language') != "en")
		    alert( "请输入实时上传路径。" );
        document.dwGateSetting.WebPORT.focus();
        return false;
	}
	if(DetectDevicepath=='')
	{
		 if($.cookie('language') === "en")
		    alert( "Please input DetectDevicepath." );
		if($.cookie('language') != "en")
		    alert( "请输入定时连接路径。" );
        document.dwGateSetting.WebPORT.focus();
        return false;
	}
	if(!valid_port0(WebPORT))
    {
        if($.cookie('language') === "en")
		    alert( "Please input server port right." );
		if($.cookie('language') != "en")
		    alert( "请正确输入服务器PORT。\n温馨提示：只能输入1-65534之间的整数。" );
        document.dwGateSetting.WebPORT.focus();
        return false;
    }
    if(!checkIp(Camera0ADDR))
    {
        if($.cookie('language') === "en")
		    alert( "Please input Camera 1 ADDR right." );
		if($.cookie('language') != "en")
		    alert( "请正确输入一号门摄像头IP。" );
        document.dwGateSetting.Camera0ADDR.focus();
        return false;
    }
	if(!valid_port0(Camera0PORT))
    {
        if($.cookie('language') === "en")
		    alert( "Please input Camera 1 port right." );
		if($.cookie('language') != "en")
		    alert( "请正确输入一号门摄像头PORT。\n温馨提示：只能输入1-65534之间的整数。" );
        document.dwGateSetting.Camera0PORT.focus();
        return false;
    }
	if(!checkIp(Camera1ADDR))
    {
        if($.cookie('language') === "en")
		    alert( "Please input Camera 2 ADDR right." );
		if($.cookie('language') != "en")
		    alert( "请正确输入二号门摄像头IP。" );
        document.dwGateSetting.Camera1ADDR.focus();
        return false;
    }
	if(!valid_port0(Camera1PORT))
    {
        if($.cookie('language') === "en")
		    alert( "Please input Camera 2 port right." );
		if($.cookie('language') != "en")
		    alert( "请正确输入二号门摄像头PORT。\n温馨提示：只能输入1-65534之间的整数。" );
        document.dwGateSetting.Camera1PORT.focus();
        return false;
    }
	    if(!checkIp(Camera2ADDR))
    {
        if($.cookie('language') === "en")
		    alert( "Please input Camera 3 ADDR right." );
		if($.cookie('language') != "en")
		    alert( "请正确输入三号门摄像头IP。" );
        document.dwGateSetting.Camera2ADDR.focus();
        return false;
    }
	if(!valid_port0(Camera2PORT))
    {
        if($.cookie('language') === "en")
		    alert( "Please input Camera 3 port right." );
		if($.cookie('language') != "en")
		    alert( "请正确输入三号门摄像头PORT。\n温馨提示：只能输入1-65534之间的整数。" );
        document.dwGateSetting.Camera2PORT.focus();
        return false;
    }
	if(!checkIp(Camera3ADDR))
    {
        if($.cookie('language') === "en")
		    alert( "Please input Camera 4 ADDR right." );
		if($.cookie('language') != "en")
		    alert( "请正确输入四号门摄像头IP。" );
        document.dwGateSetting.Camera3ADDR.focus();
        return false;
    }
	if(!valid_port0(Camera3PORT))
    {
        if($.cookie('language') === "en")
		    alert( "Please input Camera 4 port right." );
		if($.cookie('language') != "en")
		    alert( "请正确输入四号门摄像头PORT。\n温馨提示：只能输入1-65534之间的整数。" );
        document.dwGateSetting.Camera3PORT.focus();
        return false;
    }
    if(!checkAllNum(reQusttime)||reQusttime.length<1)
    {
        alert( "间隔时间输入错误，只能是1-8位数字，请重新输入。" );
        document.dwGateSetting.reQusttime.focus();
        return false;
    }
	var downArr='{"action":"dwdownserver","WebADDR":"'+WebADDRv+'","WebPORT":"'+WebPORT+'","Camera0ADDR":"'+Camera0ADDRv+'","Camera0PORT":"'+Camera0PORT+'","Camera1ADDR":"'+Camera1ADDRv+'","Camera1PORT":"'+Camera1PORT+'","Camera2ADDR":"'+Camera2ADDRv+'","Camera2PORT":"'+Camera2PORT+'","Camera3ADDR":"'+Camera3ADDRv+'","Camera3PORT":"'+Camera3PORT+'","cmdresultpath":"'+cmdresultpath+'","realtimepath":"'+realtimepath+'","DetectDevicepath":"'+DetectDevicepath+'","reQusttime":"'+reQusttime+'"}';	
    ajaxDownLoadserver(downArr);
	return true; 
}
/*
function dwGatesubmit()
{
    if(dwGateSettingCheck()) document.getElementById("dwGateSetting").submit();
}
*/
function ajaxDownLoadserver(downArr)
{
//	if(!dwGateSettingCheck()) return false;
//	var downArr='{"action":"dwdownserver"}';
	$.ajax({
        url: "/dw/Dwbrowser",
        type: "POST",
        timeout: 180000,
        data: downArr,
        dataType: "text",
//          async: true,
        error: function()
        {
            $('#massage_text').text('网络错误。'); 
            return false;
        },
        complete: function()
        {              
            if (status === 'timeout')
            {
                $('#massage_text').text('超时。');
                this.abort();
            }
        },
        success: function(deReturn)
        {
		    alert("deReturn:"+deReturn);
//			if(deReturn==='success')
			if(deReturn==="success")
			{
			    alert('下发完成。');
				settab();
//			    self.setTimeout(window.location.href='/door/serversetting.php',6000);
			}else if(deReturn==="fail")
			{
			    alert('下发失败。');
				settab();
//			    self.setTimeout(window.location.href='/door/serversetting.php',6000);
			}else if(deReturn==="fail01")
			{
			    alert('输入为空或太长,下发失败。');
				settab();
//			    self.setTimeout(window.location.href='/door/serversetting.php',6000);
			}
		}
	});	
}
/*
function dwDownLoad()
{    	
//	if(!dwGateSettingCheck()) return false;	
//	dwGatesubmit();
//	var gatenum=document.dwGateSetting.gatenum.value;
	ajaxDownLoadserver();	
}
*/
function settab()
{
	var data = "{\"action\":\"dwgetservertab\"}";
	$.ajax
	({
        url: "/dw/Dwbrowser",
        type: "POST",
        timeout: 180000,
        data: data,
        dataType: "text",
//			async: true,
        error: function()
		{
		    $('#massage_text').text('网络错误。'); 
            return false;
        },
        complete: function()
		{              
            if (status === 'timeout')
			{
                $('#massage_text').text('超时。');
				this.abort();
            }
        },
        success: function(deReturn)
		{            
			var servertab =jQuery.parseJSON(deReturn);
            if(servertab['s1_0']!=='') document.dwGateSetting.WebADDR.value = servertab['s1_0'];
            if(servertab['s1_1']!=='') document.dwGateSetting.WebPORT.value = servertab['s1_1'];				
            if(servertab['s1_2']!=='') document.dwGateSetting.cmdresult.value = servertab['s1_2']; 
			if(servertab['s1_3']!=='') document.dwGateSetting.realtime.value = servertab['s1_3'];
			if(servertab['s1_4']!=='') document.dwGateSetting.DetectDevice.value = servertab['s1_4'];
			if(servertab['s1_5']!=='') document.dwGateSetting.Camera0ADDR.value = servertab['s1_5'];
			if(servertab['s1_6']!=='') document.dwGateSetting.Camera0PORT.value = servertab['s1_6'];				
            if(servertab['s1_7']!=='') document.dwGateSetting.Camera1ADDR.value = servertab['s1_7']; 
			if(servertab['s1_8']!=='') document.dwGateSetting.Camera1PORT.value = servertab['s1_8'];
			if(servertab['s1_9']!=='') document.dwGateSetting.Camera2ADDR.value = servertab['s1_9'];
			if(servertab['s1_10']!=='') document.dwGateSetting.Camera2PORT.value = servertab['s1_10'];				
            if(servertab['s1_11']!=='') document.dwGateSetting.Camera3ADDR.value = servertab['s1_11']; 
			if(servertab['s1_12']!=='') document.dwGateSetting.Camera3PORT.value = servertab['s1_12'];
			if(servertab['s1_13']!=='') document.dwGateSetting.reQusttime.value = servertab['s1_13'];
			if(servertab['s1_14']!=='') document.dwGateSetting.sVersion.value = servertab['s1_14'];	
	    }
    });	
}

function ajaxGetControlerNum()
{
    $.ajax({
        url: "/dw/Dwbrowser",
        type: "POST",
        timeout: 180000,
        data: "dwgetControlerNum",
        dataType: "text",
        error: function()
		{
		    $('#massage_text').text('网络错误。'); 
            return false;
        },
        complete: function()
		{              
            if (status === 'timeout')
			{
                $('#massage_text').text('超时。');
				this.abort();
            }
        },
        success: function(deReturn)
		{
            var DcSelection_element = document.getElementById("controlerN");
            var dcSelectiontab =jQuery.parseJSON(deReturn); 
			for(var i=1;i<=dcSelectiontab.nrows;i++)
            {
				DcSelection_element.options[i-1] = new Option(dcSelectiontab['s'+i+'_0'], dcSelectiontab['s'+i+'_0']);
			}
			settab(dcSelectiontab['s1_0'],'');	
	    }
    });	
}

$(document).ready(function()
{
    settab();
	ajaxGetControlerNum();
});   

function checkfile()
{
    document.ImportPics.controlernum.value = document.ImportPics.ControlerN.value;
	var $actionobj=document.getElementById("ImportPics");
//	$actionobj=document.getElementsByTagName("ImportPics")[0];
	var $action="/dw/Dwbrowser?controlernum="+ document.ImportPics.ControlerN.value;
//	alert("11..."+$action);
	$actionobj.action=$action;
//	alert("11..."+$actionobj.action);
	$actionobj.submit();
	return true;
}

$(function()
{
		if($.cookie('logon') === "null" || !$.cookie('logon'))
		{
		    top.window.location.pathname = '/dw/index.jsp';
		}
		
  	function checkCookie()
	{
	  	var a = $.cookie('logon') === "null" || !$.cookie('logon');
	  	if(a){
	  		top.window.location.pathname = '/dw/index.jsp';
	  	}else{
		    var date = new Date();
		    date.setTime(date.getTime() + (60 * 60 * 1000));
		    $.cookie('logon',true,{expires: date});		 
		}
	}
});
</script>
</HTML>

